package com.woniu.dao;

import com.woniu.dto.ServerOrderToServer;
import com.woniu.dto.ServerToServerMenu;
import com.woniu.pojo.ServerMenu;
import com.woniu.pojo.ServerOrders;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

public interface ServerOrdersMapper {
    int deleteByPrimaryKey(Long id);

    int insert(ServerOrders record);

    int insertSelective(ServerOrders record);

    ServerOrders selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(ServerOrders record);

    int updateByPrimaryKey(ServerOrders record);

    @Select("select * from server_orders so right join servers s on so.ser_id = s.id where so.user_id=#{id}")
    @Results({
            @Result(id = true, property = "id", column = "id"),
            @Result(column = "ser_id", property = "servers", one = @One(select = "getServerToserverMenu", fetchType = FetchType.EAGER))
    })
    List<ServerOrderToServer> getServerOrdersByUserId(Long id);

    @Select("select * from servers s right join server_menu sm on s.server_menu_id = sm.id where s.id=#{ser_id}")
    @Results({
            @Result(id = true, property = "id", column = "id"),
            @Result(column = "server_menu_id", property = "serverMenu", one = @One(select = "getServerMenu", fetchType = FetchType.EAGER))
    })
    ServerToServerMenu getServerToserverMenu(Long ser_id);

    @Select("select * from server_menu where id=#{server_menu_id}")
    ServerMenu getServerMenu(Long server_menu_id);
}